﻿using Coldairarrow.Business.TD;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.TD;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.TD
{
    [Route("/TD/[controller]/[action]")]
    public class TD_ScrapController : BaseApiController
    {
        #region DI

        public TD_ScrapController(ITD_ScrapBusiness tD_ScrapBus)
        {
            _tD_ScrapBus = tD_ScrapBus;
        }

        ITD_ScrapBusiness _tD_ScrapBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<TD_Scrap>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _tD_ScrapBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<TD_Scrap> GetTheData(IdInputDTO input)
        {
            return await _tD_ScrapBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(TD_Scrap data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _tD_ScrapBus.AddDataAsync(data);
            }
            else
            {
                await _tD_ScrapBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _tD_ScrapBus.DeleteDataAsync(ids);
        }
      
        [HttpPost]
        public async Task AddScrapInfo(TD_ScrapInfo data) {
            if (data.Id.IsNullOrEmpty())
            {
                await _tD_ScrapBus.AddScrapInfo(data);
            }
            else {
                await _tD_ScrapBus.UpdateScrapInfo(data);
            }
            
        }
        [HttpPost]
        public async Task<TD_ScrapMainList> GetScrapMainList(string Id) {
            
            return await _tD_ScrapBus.GetScrapMainList(Id);
        }
        [HttpPost]
        public async Task<ScrapOutDetail> GetScrapOutDetail(string QrCode, string LocationQrCode, string MaterialQrCode) {
            return await _tD_ScrapBus.GetScrapOutDetail(QrCode, LocationQrCode, MaterialQrCode);
        }
        [HttpPost]
        public async Task<TD_Scrap> GetAllScrap(string QrCode) {
            return await _tD_ScrapBus.GetAllScrap(QrCode);
        }
        [HttpPost]
        public async Task GetAdd(TD_ScrapData data) {
            await _tD_ScrapBus.GetAdd(data);
        }
        /// <summary>
        /// 获取报废单了列表数据
        /// </summary>
        /// <param name="stockupQrCode"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<PB_UnLoadListDataDTO>> GetStockUpDetailListDataAsync(string stockupQrCode) {
            var list = await _tD_ScrapBus.GetStockUpDetailListDataAsync(stockupQrCode);
            return list;
        }
        /// <summary>
        /// 报废单移除
        /// </summary>
        /// <param name="stockupQrCode"></param>
        /// <param name="packqrocde"></param>
        /// <param name="locationId"></param>
        /// <param name="Nums"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteStockUpDetailListDataAsync(string stockupQrCode, string packqrocde,string locationId, double Nums) {
            await _tD_ScrapBus.DeleteStockUpDetailListDataAsync(stockupQrCode, packqrocde,  locationId, Nums);
        }
        /// <summary>
        /// 报废出库提交生成出库单
        /// </summary>
        /// <param name="ScrapId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SubmitScrapDataAsync(string ScrapId) {
            await _tD_ScrapBus.SubmitScrapDataAsync(ScrapId);
        }
        /// <summary>
        /// 报废单审核
        /// </summary>
        /// <param name="Id">报废单号</param>
        /// <returns></returns>
        [HttpPost]
        public async Task ToScrapexamine(string Id) {
            await _tD_ScrapBus.ToScrapexamine(Id);
        }
        [HttpPost]
        public async Task<List<Business.TD.TD_ScrapDetailDto>> GetScrapDetailDto(string Parentid, string LocationId, string MaterName) {
            var list = await _tD_ScrapBus.GetScrapDetailDto(Parentid,LocationId,MaterName);
            return list;
        }
        #endregion
    }
}